//
//  MineCenterVC.swift
//  ShareUmbrella
//
//  Created by niupark on 2017/8/12.
//  Copyright © 2017年 尧尚信息科技. All rights reserved.
//


import UIKit
import YSKit
import SWRevealViewController
import SDWebImage

class MineCenterVC: YSAppConfigController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    required convenience public init(config: YSBaseOptionConfig) {
        self.init()
        self.config = config
    }
    
    
    override func buildUI() {
        super.buildUI()
        self.tableView.ys.customize { (view) in
            view.ys.register(UserCenterInfoCell.self)
        }
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, config: YSBaseOptionConfig?) -> UITableViewCell {
        
        // let icon = UIImage.us_image(USColor.c502.color, size: CGSize(width: 20, height: 20))
        //        let iconSize = CGSize(width: 20, height: 20)
        
        // TODO 更换合适的图标
        
        if indexPath.section == 0, indexPath.row == 0 {
            return (self.tableView.ys.dequeueCell(indexPath) as UserCenterInfoCell).ys.customize { (cell) in
                cell.updateUI(config!)
            }
        }else {
            return super.tableView(tableView, cellForRowAt: indexPath, config: config)
            
        }
    }
    
    
    
    override func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
        if indexPath.section == 0, indexPath.row == 0 {
            self.ys.push(ImagePreviewViewController())
        }else if indexPath.section == 3, indexPath.row == 0 {
            self.ys.push(PointShopVC())
        }else {
            super.tableView(tableView, didSelectRowAtIndexPath: indexPath)
        }
        
    }
}

extension MineCenterVC {

}

class UserCenterInfoCell: YSAppConfigBaseCell {
    let headImageVeiw = UIImageView()
    override func setup() {
        super.setup()
        self.accessoryType = .disclosureIndicator
        self.headImageVeiw.ys.customize { (view) in
            self.contentView.addSubview(view)
            view.image = UIImage(named: "空白头像")
            view.layer.cornerRadius = 60.0/2.0
            view.layer.masksToBounds = true
            view.snp.makeConstraints({ (make) in
                make.trailing.equalTo(self.contentView).offset(-35)
                make.centerY.equalTo(self.contentView)
                make.height.width.equalTo(60)
            })
            
        }

        
        
    }
}


